 <?php
class Forum{
    
	private $ID_diskusi;
	private $ID_user;
	private $judul;
    private $isi_diskusi;
    private $tanggal_diskusi;
	 
	private $nama_event;
	private $deskripsi_event;
	private $tanggal_event; 
	
	private $judul_pengumuman;
	private $isi_pengumuman;
	private $tanggal_pengumuman;
	
	private $nama;
	private $date;
	private $t;
	private $b;
	private $y;

    private $Host;
    private $MySQLUsername;
    private $MySQLPassword;
    private $Database;
    private $Conn;
    

    //Constructor
    public function Forum()
    {
        session_start();
        $this->Host = "localhost";
        $this->MySQLUsername = "root";
        $this->MySQLPassword = "";
        $this->Database = "efutsal";

        $this->Connection();
        
        unset($this->Host);
        unset($this->MySQLUsername);
        unset($this->MySQLPassword);
        unset($this->Database);
    }


    public function Connection()
    {
        $this->Conn = @mysql_connect($this->Host,$this->MySQLUsername,$this->MySQLPassword);
        if($this->Conn)
        {
            mysql_select_db($this->Database) OR die('Could not select DB');
        }
        else
        {
            die(mysql_error());
        }  
    }
    
    public function Query($sql)
    {
        $result = mysql_query($sql); 
        if(!$result)
        {
            die(mysql_error());
        } 
        return $result;
    }
	
    
    public function Disconnect()
    {
        mysql_close($this->Conn);
    }
    
    //Escapes bad values for MySQL to prevent SQL injections.
    public function EscapeString($badstring)
    {
        if(!get_magic_quotes_gpc())
        {
            $goodstring = addslashes($badstring);
        }
        else
        {
            $goodstring = stripslashes($badstring);
        }
        $goodstring = mysql_real_escape_string($badstring);
        return $goodstring;
    }
    
	
 	public function Result_To_Array($result)
    {
        $result_array = array();
        for ($i=0; $row = mysql_fetch_array($result); $i++) 
        {
            $result_array[$i] = $row;
        }
        return $result_array;
    }
	
	public function DiskusiAnyar()
    {
       
    }
	
	public function EventAnyar()
    {
       
    }
	
	
	
	
 public function GetDate(){
	$date = getdate();
	$t = $date['mday'];
	$b = $date['mon'];
	$y = $date['year'];
	
	 $tanggal = "$y-$b-$t";
	 return $tanggal;
	 
 }		


	
 public function AddDiskusi($judul,$isi_diskusi,$tanggal_diskusi,$nama)
    {
		
		$ID = mysql_fetch_array($this->Query("SELECT MAX(ID_diskusi)+1 from `diskusi`"));
		$ID_diskusi = $ID[0];
        $judul = $this->EscapeString($judul);
		$isi_diskusi = $this->EscapeString($isi_diskusi);
		$tanggal_diskusi = $this->EscapeString($tanggal_diskusi);
		$user= mysql_fetch_array($this->Query("SELECT ID_user from `user` where username='$nama'"));
		$ID_user = $user[0];
		
        $result = $this->Query("INSERT INTO `diskusi` (ID_diskusi,ID_user,judul,isi_diskusi,tanggal_diskusi) VALUES ('$ID_diskusi','$ID_user','$judul','$isi_diskusi','$tanggal_diskusi')");
		header('location:../page/HOME_forum.php'); 
    }
	
	public function AddEvent($nama_event,$deskripsi_event,$tanggal_event,$nama)
	{
	$ID = mysql_fetch_array($this->Query("SELECT MAX(ID_event)+1 from `event`"));
		$ID_event = $ID[0];
        $nama_event = $this->EscapeString($nama_event);
		$deskripsi_event = $this->EscapeString($deskripsi_event);
		$tanggal_event = $this->EscapeString($tanggal_event);
		$user= mysql_fetch_array($this->Query("SELECT ID_user from `user` where username='$nama'"));
		$ID_user = $user[0];

        $result = $this->Query("INSERT INTO `event` (ID_event,ID_user,nama_event,deskripsi_event,tanggal_event) VALUES ('$ID_event','$ID_user','$nama_event','$deskripsi_event','$tanggal_event')");
		header('location:../page/HOME_forum.php'); 
	}
	
	
	
		public function AddPengumuman($judul_pengumuman,$isi_pengumuman,$tanggal_pengumuman,$nama)
	{
	$ID = mysql_fetch_array($this->Query("SELECT MAX(ID_pengumuman)+1 from `pengumuman`"));
		$ID_pengumuman = $ID[0];
        $judul_pengumuman = $this->EscapeString($judul_pengumuman);
		$isi_pengumuman = $this->EscapeString($isi_pengumuman);
		$tanggal_pengumuman = $this->EscapeString($tanggal_pengumuman);
		$user= mysql_fetch_array($this->Query("SELECT ID_user from `user` where username='$nama'"));
		$ID_user = $user[0];

        $result = $this->Query("INSERT INTO `pengumuman` (ID_pengumuman,ID_user,judul_pengumuman,isi_pengumuman,tanggal_pengumuman) VALUES ('$ID_pengumuman','$ID_user','$judul_pengumuman','$isi_pengumuman','$tanggal_pengumuman')");
		header('location:../page/HOME_admin.php'); 
	}
	
	
	
	}